package cn.com.huzo.webapp.controller.master;

import huzofw.common.web.controller.BaseFormController;
import cn.com.huzo.model.entities.master.ShippingTypeEntity;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import cn.com.huzo.service.master.ShippingTypeManager;

/**
 * 运输方式控制器
 *
 * @author 吴旭
 */
@Controller
public class ShippingTypeController extends BaseFormController {

    // <editor-fold defaultstate="collapsed" desc="属性">
    @Resource(name = "ShippingTypeManager")
    private ShippingTypeManager _manager;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="画面处理部分">
    /**
     * 跳转到运输方式一览画面
     * <p>
     * @return
     */
    @RequestMapping("master/shipping_type/list.html")
    public ModelAndView redirectListWnd() {
        ModelAndView view = new ModelAndView();
        view.setViewName("master.shipping_type.list.def");
        return view;
    }

    /**
     * 弹出运输方式选择画面
     * <p>
     * @return
     */
    @RequestMapping("master/shipping_type/choice.html")
    public ModelAndView redirectChoiceWnd() {
        ModelAndView view = new ModelAndView();
        view.setViewName("popup.master.shipping_type.choice.def");
        return view;
    }

    /**
     * 转到运输方式在线维护画面
     * <p>
     * @return
     */
    @RequestMapping("master/shipping_type/online/edit.html")
    public ModelAndView redirectOnlineEditWnd() {
        ModelAndView view = new ModelAndView();
        view.setViewName("popup.master.shipping_type.online_edit.def");
        return view;
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="数据处理部分">
    /**
     * 取得全部运输方式数据列表
     *
     * @return 全部运输方式数据列表
     * @throws java.lang.Exception
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "master/shipping_type/fetchAll.html",
            method = RequestMethod.POST,
            produces = {"application/xml", "application/json"})
    public @ResponseBody
    List<ShippingTypeEntity> fetchAll() throws Exception {
        return _manager.fetchAll();
    }

    /**
     * 批量保存或更新运输方式。
     *
     * @param data 要处理的运输方式数据列表
     * @return
     *
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "master/shipping_type/save.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> save(@RequestBody final Map<String, ? extends List<ShippingTypeEntity>> data) throws Exception {
        return _manager.saveLines(data);
    }

    /**
     * 增加单条运输方式。
     *
     * @param instance 要增加的的运输方式数据
     * @return 增加的数据主键
     *
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "master/shipping_type/single/save.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Long saveOne(@RequestBody final ShippingTypeEntity instance) throws Exception {
        return _manager.insert(instance);
    }

    /**
     * 删除。
     *
     * @param criterion 要删除的数据
     * @return 删除后的数据
     *
     * @throws java.lang.Exception
     */
    @RequestMapping(value = "master/shipping_type/delete.html",
            method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> delete(@RequestBody final Map<String, Object> criterion) throws Exception {
        return _manager.delete(criterion);
    }
    // </editor-fold>
}
